PRG 1.0 TXT

/*
	Gray Scale Color Correction for Post Process
*/

//-----------------------------------------------------------------------------
// [CONFIG]

include "..\program_include.ocf"

object Program
{
	ubo_data	= array /*UBO*/ {
		{ "inParams",	e_program_data.POSTPROCESS_PARAMS }
	}

	textures	= array /*ProgramTexture*/ {
		{ "unColorMap", e_texture.DIFFUSE }
	}
	
	uniforms	= array /*string*/ {
		"transform", "unTransform."
	}
}


//-----------------------------------------------------------------------------
// [VERTEX]

#version 330 core
#pragma optimize(on)

#define ATTR_POSITION	0
#define ATTR_TEXCOORD	2
#define ATTR_COLOR		1

layout(location = ATTR_POSITION)	in vec3 inPosition;
layout(location = ATTR_TEXCOORD)	in vec2 inTexcoord;


uniform struct Transform {
	mat4	Projection;
} unTransform;


out	TVertexData {
	vec2	vTexcoord;
} Output;


void main(void)
{
	gl_Position  	 = unTransform.Projection * vec4(inPosition, 1.0);
	Output.vTexcoord = inTexcoord;
}


//-----------------------------------------------------------------------------
// [FRAGMENT]

#version 330 core
#pragma optimize(on)

layout(location = 0, index = 0) out vec4	outColor;

uniform sampler2D	unColorMap;


layout (std140)
uniform inParams {
	vec3	vColor0  = vec3(0.2, 0.0, 0.5);		// 0.2, 0.17, 0.0
	vec3	vColor1  = vec3(0.4, 1.0, 0.2);
	vec3	vColor2  = vec3(2.0, 0.1, 0.1);		// 2.0, 1.7, 0.0
	float	fMix;
} unParams;


in	TVertexData {
	vec2	vTexcoord;
} Input;

#define sqr(x)	((x)*(x))


float Rnd(in vec2 x)
{
    int n = int(x.x * 40.0 + x.y * 6400.0);
    n = (n << 13) ^ n;
    return 1.0 - float( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0;
}


vec3 RndColor(in vec3 cl)
{
	int		n = int(cl.r * 40.0 + cl.g * 260.0 + cl.b * 640.0);
	n = (n << 11) ^ n;
	float	k = float( (n * n * 12345 + 33) & 0x7fffffff ) * 0.0000000009;
	return vec3(k);
}

vec3 ColorScale(in vec3 color, float n)
{
	const vec3 factor = vec3(0.27, 0.67, 0.06);

	float	a  = dot( factor, color );
	vec3	c1 = mix( unParams.vColor0, unParams.vColor1, a);
	vec3	c2 = mix( unParams.vColor1, unParams.vColor2, a);
	return RndColor( mix( c1, c2, a) );
}


vec3 Filter(in vec3 color, in vec2 texcoord)
{
	return ( ColorScale( color, Rnd(texcoord) ) - color ) * unParams.fMix + color;
}


void main(void)
{
	vec4	color = texture( unColorMap, Input.vTexcoord );
	outColor = vec4( Filter( color.rgb, Input.vTexcoord ), color.a );
}

// [END]
